﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Reflection;
using Microsoft.Internal;

namespace System.ComponentModel.Composition.ReflectionModel
{
    internal static class ReflectionExtensions
    {
        public static ReflectionMember ToReflectionMember(this MemberInfo member)
        {
            Assumes.NotNull(member);

            switch (member.MemberType)
            {
                case MemberTypes.Field:
                    return new ReflectionField((FieldInfo)member);

                case MemberTypes.Property:
                    return new ReflectionProperty((PropertyInfo)member);

                case MemberTypes.NestedType:
                case MemberTypes.TypeInfo:
                    return new ReflectionType((Type)member);

                default:
                    Assumes.IsTrue(member.MemberType == MemberTypes.Method);
                    return new ReflectionMethod((MethodInfo)member);
            }
        }

        public static ReflectionWritableMember ToReflectionWritableMember(this MemberInfo member)
        {
            if (member.MemberType == MemberTypes.Property)
            {
                return new ReflectionProperty((PropertyInfo)member);
            }

            return new ReflectionField((FieldInfo)member);
        }
    }
}
